#!/usr/bin/env python3
"""
这个脚本用于修复visualization.py中LDPC状态的日志问题，将日志记录修改为界面显示
"""

import re

def main():
    # 读取visualization.py文件内容
    with open('visualization.py', 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 修改LDPC日志记录，约在1475-1485行
    pattern = r'# 检查LDPC状态\s+ldpc_status_value = .*?else:\s+# 记录具体状态值到日志\s+logger\.warning\(\s+f"发现无效LDPC状态.*?\)\s+ldpc_status = "无效LDPC状态"'
    replacement = '# 检查LDPC状态\n            ldpc_status_value = frame_check_ldpc & 0xFF\n            if ldpc_status_value == 0:\n                ldpc_status = "LDPC成功"\n            elif ldpc_status_value == 1:\n                ldpc_status = "LDPC失败"\n            else:\n                # 直接在状态文本中显示具体状态值，不写入日志\n                ldpc_status = f"无效LDPC状态(0x{ldpc_status_value:02X})"'
    
    content = re.sub(pattern, replacement, content, flags=re.DOTALL)
    
    # 保存修改后的内容
    with open('visualization.py', 'w', encoding='utf-8') as f:
        f.write(content)
    
    print("修复完成：LDPC日志记录已改为界面显示")

if __name__ == "__main__":
    main() 